package meow

import org.compass.core.engine.SearchEngineQueryParseException

// Seachableプラグインのコントローラをまんまパクってきました。
class SearchController {
  def searchableService
  /**
   * Index page with search form and results
   */
  def index = {
    if (!params.q?.trim()) {
      return [:]
    }
    try {
      // 全文検索にしないで，Statusだけを検索対象にしときます。
      return [searchResult: Status.search(params.q, params)]
    }
    catch (SearchEngineQueryParseException ex) {
      return [parseException: true]
    }
  }

  /**
   * Perform a bulk index of every searchable object in the database
   */
  def indexAll = {
    Thread.start {
      searchableService.index()
    }
    render("bulk index started in a background thread")
  }

  /**
   * Perform a bulk index of every searchable object in the database
   */
  def unindexAll = {
    searchableService.unindex()
    render("unindexAll done")

  }
}